#!/usr/bin/env python3

def getsum(num):
    answer = 0
    for char in str(num):
        answer += int(char)
    return answer
    
answer = 0
for a in range(1,101):
    for b in range(1,101):
        s = getsum(a**b)
        if s > answer:
            answer = s
            
print(answer)